package com.oba.king.hospitalinfo.hospitalinformation;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import com.oba.base.dao.DBDataModel;
import com.oba.base.service.BaseBean;

public class HospitalInformationBean extends BaseBean<HospitalInformation,HospitalInformationService> {
	
	private HospitalInformation hospitalInformation;
	private DBDataModel hospitalList = DBDataModel.create();
	private boolean showEdit = false; 
	private static final String ADD_NEW_HOSPITAL_PATH = "/hospitalinfo/hospitalInformationAdd.jspx";
	private static final String SHOW_ORIGINAL_PATH = "/hospitalinfo/hospitalinformationShow.jspx"; 
	String hospitalName;
	private List<SelectItem> hospitalInfoList;
	private HospitalCondition hospitalCondition;

	@Override
	public String doFind() {
		hospitalList.find(getService().getDao().buildAll());		
		return null;
	}
	
	public void doAddRow() {
		hospitalInformation =new HospitalInformation();
		hospitalInformation.setNewBo(true);
		this.goTarget(this.ADD_NEW_HOSPITAL_PATH);		
	}
	
	public void doSave(){
		this.getService().save(hospitalInformation);
		this.doFind();
		this.goTarget(this.SHOW_ORIGINAL_PATH);
		this.doFind();
	}
	
	public void doEditRow(){
		if(hospitalList.isRowAvailable()) {
			hospitalInformation = (HospitalInformation) hospitalList.getRowData();
			this.goTarget(ADD_NEW_HOSPITAL_PATH);			
		}
	}
	
	public void doDeleteRow() {
		if(hospitalList.isRowAvailable()) {
			getService().del((HospitalInformation)hospitalList.getRowData());
			doFind();
		}
	}
	
	@Override
	public void init() {
		hospitalList.find(getService().getDao().buildAll());
		
		hospitalInfoList = new ArrayList<SelectItem>();
//		hospitalInfoList.add(new SelectItem(null,"全部"));
		//System.out.println(hospitalList.getAllData().get(0).getId());
		hospitalInformation = new HospitalInformation();
		hospitalCondition = new HospitalCondition();
	}
	
	
	public void srchByHospitalName(){
		System.out.println("Start HospitalInformationBean srchByHospitalName()>>>>");
		if(hospitalName != null && !hospitalName.trim().equals("")){
			this.hospitalList.find(this.getService().getDao().srchByHospitalNm(hospitalName));
		}
		System.out.println("Start HospitalInformationBean srchByHospitalName()>>>>");
	}
	/**
	 * 模糊查询：根据hospitalCondition中的属性
	 */
	public void srchByHospitalCondition(){
		System.out.println("Start HospitalInformationBean srchByHospitalName()>>>>");
		if(hospitalCondition != null){
			this.hospitalList.find(this.getService().getDao().srchByHospitalCondition(hospitalCondition));
		}
		System.out.println("Start HospitalInformationBean srchByHospitalName()>>>>");
	}
	/**
	 *页面返回
	 */
	public void doRturnShow(){
		this.goTarget(this.SHOW_ORIGINAL_PATH);
		this.cleanButton();
	}
	
	//页面点击清空按钮的时候
	public void cleanButton(){
		this.hospitalCondition = new HospitalCondition();
//		this.doFind();
	}
	
	public boolean isShowEdit() {
		return showEdit;
	}
	
	public void closeEdit() {
		showEdit = false;
	}
	
	public DBDataModel getHospitalList() {
		return hospitalList;
	}

	public void setHospitalList(DBDataModel hospitalList) {
		this.hospitalList = hospitalList;
	}

	public String getHospitalName() {
		return hospitalName;
	}

	public void setHospitalName(String hospitalName) {
		this.hospitalName = hospitalName;
	}
	
	public HospitalCondition getHospitalCondition() {
		return hospitalCondition;
	}

	public void setHospitalCondition(HospitalCondition hospitalCondition) {
		this.hospitalCondition = hospitalCondition;
	}

	public HospitalInformation getHospitalInformation() {
		return hospitalInformation;
	}

	public void setHospitalInformation(HospitalInformation hospitalInformation) {
		this.hospitalInformation = hospitalInformation;
	}	

}
